package com.beemans.topon.demo.ui.fragments

import android.view.View
import com.beemans.common.ext.init
import com.beemans.common.ui.fragments.CommonFragment
import com.beemans.topon.demo.R
import com.beemans.topon.demo.data.NativeAdListEntity
import com.beemans.topon.demo.databinding.FragmentNativeAdListBinding
import com.beemans.topon.demo.ui.adapters.NativeAdListAdapter
import com.tiamosu.databinding.delegate.lazyDataBindingOrNull
import com.tiamosu.databinding.page.DataBindingConfig

/**
 * @author ti
 * @date 2022/11/23.
 */
class NativeAdListFragment : CommonFragment() {
    private val dataBinding: FragmentNativeAdListBinding? by lazyDataBindingOrNull { }
    private val adapter by lazy { NativeAdListAdapter(this) }

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.fragment_native_ad_list)
    }

    override fun initView(rootView: View?) {
        dataBinding?.nativeAdListRv?.init(bindAdapter = adapter)
    }

    override fun doBusiness() {
        val list = mutableListOf<NativeAdListEntity>()
        for (i in 0..20) {
            val type =
                if (i % 4 == 0) NativeAdListAdapter.TYPE_AD else NativeAdListAdapter.TYPE_CONTENT
            list.add(NativeAdListEntity(type))
        }
        adapter.setList(list)
    }
}